package br.edu.univas.locadoragraph.bean;


import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.context.FacesContext;

import org.primefaces.model.DualListModel;

import br.edu.univas.locadoragraph.dao.ActorDAO;
import br.edu.univas.locadoragraph.to.ActorTO;

@ManagedBean(name="actorBean")
@RequestScoped 
public class ActorBean implements Serializable{
	
	private ActorTO actorTo;
	private ActorDAO actorDao;
	private DualListModel<String> listActors;  
	//private List<String> actorSelected; 
	

	public ActorBean() {
		actorTo = new ActorTO();
		actorDao = new ActorDAO();
		
		 //Cities  
        List<String> actorsSource = new ArrayList<String>();  
        List<String> actorsTarget = new ArrayList<String>();
          
        actorsSource.add("Istanbul");  
        actorsSource.add("Ankara");  
        actorsSource.add("Izmir");  
        actorsSource.add("Antalya");  
        actorsSource.add("Bursa"); 
        actorsSource.add("Istanbula");  
        actorsSource.add("Ankaraa");  
        actorsSource.add("Izmira");  
        actorsSource.add("Antalyaa");  
        actorsSource.add("Bursaa");  
        
          
        listActors = new DualListModel<String>(actorsSource, actorsTarget); 
        //actorSelected = new ArrayList<String>();
	}
	
	
	public DualListModel<String> getListActors() {
		return listActors;
	}

	public void setListActors(DualListModel<String> listActors) {
		this.listActors = listActors;
	}

	
	
	
	/*CRUD*/
	public void saveActor(){
		
		 if(this.actorDao.saveActorGraph(this.actorTo)){
				FacesContext.getCurrentInstance().addMessage(null,new FacesMessage("Ator Cadastrado com Sucesso!")); 
			}else{
				FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR,"Houve algum erro no cadastro do ator!", this.actorTo.getName()));  
			}
		
	}
	/*Responsavei pela transição Bean and To*/
	public ActorTO getActorTo() {
		return actorTo;
	}

	public void setActorTo(ActorTO actorTo) {
		this.actorTo = actorTo;
	}

	public ActorDAO getActorDao() {
		return actorDao;
	}

	public void setActorDao(ActorDAO actorDao) {
		this.actorDao = actorDao;
	}
	
	
	

}